package com.hbsx.why.ui.mine;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.Window;


import com.hbsx.why.R;
import com.hbsx.why.utils.AppUtilsDemo;

import butterknife.ButterKnife;

/**
 * Created by User on 2017/4/7.
 */

public class ShareActivity extends Activity implements View.OnClickListener {
    private Context context = this;
    // QQ
    //0只下载，其他值是活动的id
    private String activity_id;
    //    private Tencent mTencent;
    private String activity_title = "文化云";
    private String activity_desc;
    private String download_url, flag;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.ui_share_main);
        ButterKnife.setDebug(true);
        activity_id = getIntent().getStringExtra("activity_id");
        activity_desc = getIntent().getStringExtra("activity_desc");
        flag = getIntent().getStringExtra("flag");
        if (activity_desc == null) {
            activity_desc = "文化云";
        }
//        download_url = HttpAdapter.BASE_URL +"interface.do?method=apkdownload&activity_id=" + activity_id+"&flag="+flag;
//        AppUtilsDemo.wxApi = WXAPIFactory.createWXAPI(this, AppUtilsDemo.WX_APPID, true);
//        AppUtilsDemo.wxApi.registerApp(AppUtilsDemo.WX_APPID);
//        mTencent = Tencent.createInstance(AppUtilsDemo.QQ_appid, this.getApplicationContext());
        findViewById(R.id.WX_share1).setOnClickListener(this);
        findViewById(R.id.WX_share2).setOnClickListener(this);
        findViewById(R.id.QQ_share1).setOnClickListener(this);
        findViewById(R.id.QQ_share2).setOnClickListener(this);
        findViewById(R.id.share_view).setOnClickListener(this);
    }

    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.WX_share1:
                AppUtilsDemo.isLogin = false;
                wechatShare(0);
                break;
            case R.id.WX_share2:
                AppUtilsDemo.isLogin = false;
                wechatShare(1);
                break;
            case R.id.QQ_share1:
                QQshare(0);
                break;
            case R.id.QQ_share2:
                QQshare(1);
                break;
            case R.id.share_view:
                finish();
                break;

        }
    }

    /**
     * 微信分享
     *
     * @param flag 0为微信好友 1为朋友圈
     */
    private void wechatShare(int flag) {
//        WXWebpageObject webpage = new WXWebpageObject();
//        webpage.webpageUrl = download_url;
//        WXMediaMessage msg = new WXMediaMessage(webpage);
//        msg.title = activity_title;
//        msg.description = activity_desc;
//        // 这里替换一张自己工程里的图片资源
//        Bitmap thumb = BitmapFactory.decodeResource(getResources(),
//                R.mipmap.ic_launcher);
//        msg.setThumbImage(thumb);
//
//        SendMessageToWX.Req req = new SendMessageToWX.Req();
//        req.transaction = String.valueOf(System.currentTimeMillis());
//        req.message = msg;
//        req.scene = flag == 0 ? SendMessageToWX.Req.WXSceneSession
//                : SendMessageToWX.Req.WXSceneTimeline;
//        AppUtilsDemo.wxApi.sendReq(req);
    }

    /**
     * QQ分享
     *
     * @param flag 1为空间分享  0为 好友分享
     */
    private void QQshare(int flag) {
//        ShareListener myListener = new ShareListener();
//
//        final Bundle params = new Bundle();
//        if (flag == 1) {
//            params.putInt(QQShare.SHARE_TO_QQ_EXT_INT, QQShare.SHARE_TO_QQ_FLAG_QZONE_AUTO_OPEN);
//        } else {
//            params.putInt(QQShare.SHARE_TO_QQ_KEY_TYPE, QQShare.SHARE_TO_QQ_TYPE_DEFAULT);
//        }
//        params.putString(QQShare.SHARE_TO_QQ_TITLE, activity_title);
//        params.putString(QQShare.SHARE_TO_QQ_SUMMARY, activity_desc);
////        params.putString(QQShare.SHARE_TO_QQ_SUMMARY, "安徽省图书馆大众文化圈");
//        params.putString(QQShare.SHARE_TO_QQ_TARGET_URL, download_url);
//        params.putInt(QQShare.SHARE_TO_QQ_IMAGE_URL, R.mipmap.ic_launcher);
//        mTencent.shareToQQ(this, params, myListener);
    }

//    private class ShareListener implements IUiListener {
//
//        @Override
//        public void onCancel() {
//            // TODO Auto-generated method stub
//            Toast.makeText(context, "取消", Toast.LENGTH_SHORT).show();
//        }
//
//        @Override
//        public void onComplete(Object arg0) {
//            Toast.makeText(context, "成功", Toast.LENGTH_SHORT).show();
//            finish();
//        }
//
//        @Override
//        public void onError(UiError arg0) {
//            Toast.makeText(context, "失败", Toast.LENGTH_SHORT).show();
//            finish();
//        }
//
//    }
//
//    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
//        ShareListener myListener = new ShareListener();
//        Tencent.onActivityResultData(requestCode, resultCode, data, myListener);
//    }
}
